﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Semantics;

public partial class CreateNode : WikiPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!base.IsAuthorized())
            return;
        if (IsPostBack)
            return;
        string url = Request.Url.ToString();
        int pos = url.IndexOf('?');
        if (pos != -1)
        {
            string quest = url.Substring(url.IndexOf('?') + 1);
            this.Title = "创建节点'"+quest+"'";
            this.TextBoxNodeLabel.Text = quest;
            string hint = "workmode=createnode;label=" + quest;
            byte[] bytes = System.Text.UnicodeEncoding.Unicode.GetBytes(hint);
        }
    }
    protected void ButtonCreateNode_Click(object sender, EventArgs e)
    {
        this.TextBoxNodeLabel.Text = this.TextBoxNodeLabel.Text.Trim();
        if (this.TextBoxNodeLabel.Text.Length == 0)
        {
            base.ShowError("请输入标签");
            return;
        }
        Node exist = base.GraphDatabase.ResolveNode(this.TextBoxNodeLabel.Text);
        if (exist != null)
        {
            base.ShowError("Node '" + exist + "' already exist!");
            return;

        }
        Node node = base.GraphDatabase.AddNode(this.TextBoxNodeLabel.Text);
        Response.Redirect("WikiNode.aspx?nid=" + node.Id);
    }
}